< previous page page_525 next page >

Page 525
  (EmployeeID  TEXT(10) CONSTRAINT PKEmployeeID PRIMARY KEY,
   LastName    TEXT(30),
   FirstName   TEXT(30),
   LoginName   TEXT(15),
   JobTitle    TEXT(20) CONSTRAINT FKJobTitle REFERENCES JobsTable(JobTitle),
   Department  TEXT(10)
   );
// use alter table to add and drop a constraint
ALTER TABLE EmpsTable ADD CONSTRAINT FKMoreJobs
   FOREIGN KEY (JobTitle) REFERENCES JobsTable(JobTitle);
ALTER TABLE EmpsTable DROP CONSTRAINT FKMoreJobs;

// show empty table
SELECT * FROM JobsTable;
SELECT * FROM EmpsTable;
SELECT * FROM PayGrades;
SELECT * FROM BudgetTrack;
// eof
In today's lesson, you saw SQL keywords that create and alter tables and establish table indexes and relationship constraints. Now you are ready for tomorrow's lesson, in which you learn the SQL keywords that you can use to add data to the tables you have created. You'll also see keywords that you can use to copy tables, including the data.
Summary
In today's lesson you learned how to create, alter, and delete database table structures using DDL (Data Definition Language) SQL keywords. You also learned that using DDL statements to build tables, create indexes, and establish relationships is an excellent way to automatically document table layouts. You learned how to maintain database structures using the following DDL keywords:
·CREATE TABLE enables you to create entirely new tables in your existing database.
·DROP TABLE enables you to completely remove a table, including any data that is already in the table.
·ALTER TABLE enables you to ADD a new column or DROP an existing column from the table without losing existing data in the other columns.
·CREATE INDEX and DROP INDEX enable you to create indexes that can enforce data integrity or speed data access.
· The CONSTRAINT clause can be added to the CREATE TABLE or ALTER TABLE statement to define relationships between tables using the FOREIGN KEY clause.

 
< previous page page_525 next page >

If you like this book, buy it!